<template>
  <l-content :app="app" v-loading="loading">
    <el-card>
      <el-form label-width="150px" :model="form" ref="form" :rules="rules">
        <el-form-item>
          <el-radio-group v-model="form.type">
            <el-radio-button label="1">PNR导入</el-radio-button>
            <el-radio-button label="2">PNR文本解析</el-radio-button>
            <el-radio-button label="3">关联订单导入</el-radio-button>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="PNR导入" v-if="form.type === '1'" prop="pnrCode" key="pnrCode">
          <el-input v-model="form.pnrCode" placeholder="请输入小编码" class="w600"/>
        </el-form-item>
        <el-form-item label="Office号" key="officeNo" v-if="form.type === '1'">
          <el-select v-model="form.officeNo" class="w600" clearable>
            <el-option v-for="item in options.etermGroup" :key="item" :label="item" :value="item"/>
          </el-select>
        </el-form-item>
        <el-form-item label="PNR解析" v-else-if="form.type === '2'" prop="pnrText" key="pnrText">
          <el-input type="textarea" class="w600"
                    v-model="form.pnrText"
                    :autosize="{ minRows: 6, maxRows: 12}"/>
        </el-form-item>
        <el-form-item label="关联订单导入" v-else-if="form.type === '3'" prop="localOrderId" key="localOrderId">
          <el-input v-model="form.localOrderId" placeholder="关联订单导入" class="w600"/>
        </el-form-item>
        <el-form-item label="导入原因">
          <el-select v-model="form.reason" class="w600">
            <el-option v-for="item in options.importType" :key="item.key" :value="item.key" :label="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item label="备注">
          <el-input type="textarea" class="w600"
                    v-model="form.remarks"
                    :autosize="{ minRows: 4, maxRows: 8}"/>
        </el-form-item>
        <el-form-item>
          <easy-button @click="onNext">下一步</easy-button>
        </el-form-item>
      </el-form>
    </el-card>
  </l-content>
</template>

<script>
import Tab from '@/classes/Tab'

export default {
  name: 'OrderSupplement',
  props: {
    app: {
      type: Object,
      default () {
        return {}
      }
    }
  },
  data () {
    return {
      options: {
        importType: [],
        etermGroup: []
      },
      loading: false,
      form: {
        officeNo: null,
        type: '1',
        pnrCode: '',
        pnrText: '',
        localOrderId: '',
        reason: '',
        remarks: ''
      },
      rules: {
        pnrCode: this.$checkRules.orderSupplement.pnrCode,
        pnrText: this.$checkRules.orderSupplement.pnrText,
        localOrderId: this.$checkRules.orderSupplement.localOrderId
      }
    }
  },
  created () {
    this.$service.options.getImportType().then(res => {
      this.options.importType = res.data
    })
    this.$service.eterm.queryAllGroupList().then(res => {
      this.options.etermGroup = res.data
    })
  },
  methods: {
    onNext (done) {
      this.$refs['form'].validate((valid) => {
        // 校验通过
        if (valid) {
          this.$service.order.supplementOrder(this.form).then(res => {
            this.$emit('changeApp', new Tab({key: 'airOrderManage.orderSupplementDetail', extra: {detail: res.data}}))
          }).finally(done)
        } else {
          done()
        }
      })
    }
  }
}
</script>

<style></style>
